package com.usv.drawer.impl;

import com.usv.drawer.DifferenceDrawer;
import com.usv.point.Point;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class DifferenceFileDrawer implements DifferenceDrawer {
    
    @Override
    public void drawFrame(BufferedImage bufImgResult, Point start,
            Point end, Color color) {
        int x1 = start.getX();
        int x2 = end.getX();
        int y1 = start.getY();
        int y2 = end.getY();
        
        Graphics graphics = bufImgResult.getGraphics();
        graphics.setColor(color);
        
        graphics.drawRect(x1, y1, x2 - x1, y2 - y1);
        
        try {
            ImageIO.write(bufImgResult, "png", new File("image.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    public void fillIgnore(BufferedImage bufImgResult, Rectangle rec) {
        int x = rec.x;
        int y = rec.y;
        int height = rec.height;
        int width = rec.width;
        
        Graphics graphics = bufImgResult.getGraphics();
        graphics.setColor(Color.WHITE);
        
        graphics.clearRect(x, y, width, height);
    }
}
